package bb.lanxing.adapter.routebook

import bb.lanxing.R
import bb.lanxing.databinding.ItemLushuSynchronizedListBinding
import bb.lanxing.model.database.RouteBook
import bb.lanxing.util.CommonUtil
import bb.lanxing.util.SportTypeResUtil
import bb.lanxing.util.image.GlideUtils
import bb.lanxing.util.text.TextUtils
import bb.lanxing.view.UserAvatarView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import gov.nist.core.Separators

class DeviceRouteBookAdapter :
    BaseQuickAdapter<RouteBook, BaseDataBindingHolder<ItemLushuSynchronizedListBinding>>(
        R.layout.item_lushu_synchronized_list
    ), LoadMoreModule {
    override fun convert(
        holder: BaseDataBindingHolder<ItemLushuSynchronizedListBinding>, item: RouteBook
    ) {
        val dataBinding = holder.dataBinding
        dataBinding?.apply {
            val imageUrl = item.imageUrl
            val title: String = item.title ?: ""
            if (!TextUtils.isEmptyOrNull(imageUrl)) {
                GlideUtils.companion.loadImage(context, imageUrl, ivMap)
            } else {
                ivMap.setImageResource(R.drawable.bg_summary_default_map)
            }
            userAvatar.setAvatarMode(UserAvatarView.AVATAR_SIZE_24);
            userAvatar.setAvatarForUrl(item.userAvatar);
            userAvatar.goToUserInfo(item.userId);
            ivSportType.setImageResource(SportTypeResUtil.getRoundTypeIcon(item.sport));
            tvTitle.text = title
            tvDistance.text = CommonUtil.getFormatDistance(item.distance)
            tvLushuId.text = Separators.POUND + item.serverId
        }
    }
}